// Find1stNonRepeat.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>


int Find1stNonRepeated(TCHAR str[], int nLen)
{
    int nCurPos = 0;
    BOOL bRepeat = FALSE;
    while(nCurPos + 1 != nLen)
    {
        bRepeat = FALSE;
        for(int n=0;n<nCurPos; n++)
        {
            if(str[n] == str[nCurPos])
            {
                bRepeat = TRUE;
                break;
            }
        }
        if(!bRepeat)
        {
            for(int i = nCurPos +1 ; i< nLen; i++ )
            {
                if(str[i] == str[nCurPos])
                {
                    bRepeat = TRUE;
                    break;
                }
            }
        }

        if(!bRepeat)
        {
                
            wprintf_s(L"Found the non-repeated char : %c in pos %d", str[nCurPos], nCurPos);
            return nCurPos;
        }
        else
        {
            nCurPos++;
        }


    }    
    wprintf_s(L"Can't Found the non-repeated char \n");
    return -1;
}


int _tmain(int argc, _TCHAR* argv[])
{
    int nPos = -1;
    TCHAR* pstrInput = L"tt is a good gidle apples";

    nPos = Find1stNonRepeated(pstrInput, wcslen(pstrInput));
    getchar();
    return 0;
}

